package com.ruoyi.edu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.edu.api.domain.EduVideo;
import com.ruoyi.edu.service.IEduVideoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 课程视频Controller
 *
 * @author isahino
 * @date 2023-09-16
 */
@RestController
@RequestMapping("/video")
public class EduVideoController extends BaseController {
    @Autowired
    private IEduVideoService eduVideoService;

    /**
     * 查询课程视频列表
     */
    @RequiresPermissions("edu:video:list")
    @GetMapping("/list")
    public TableDataInfo list(EduVideo eduVideo) {
        startPage();
        List<EduVideo> list = eduVideoService.selectEduVideoList(eduVideo);
        return getDataTable(list);
    }

    /**
     * 导出课程视频列表
     */
    @RequiresPermissions("edu:video:export")
    @Log(title = "课程视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduVideo eduVideo) {
        List<EduVideo> list = eduVideoService.selectEduVideoList(eduVideo);
        ExcelUtil<EduVideo> util = new ExcelUtil<>(EduVideo.class);
        util.exportExcel(response, list, "课程视频数据");
    }

    /**
     * 获取课程视频详细信息
     */
    @RequiresPermissions("edu:video:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(eduVideoService.selectEduVideoById(id));
    }

    /**
     * 新增课程视频
     */
    @RequiresPermissions("edu:video:add")
    @Log(title = "课程视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduVideo eduVideo) {
        return toAjax(eduVideoService.insertEduVideo(eduVideo));
    }

    /**
     * 修改课程视频
     */
    @RequiresPermissions("edu:video:edit")
    @Log(title = "课程视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduVideo eduVideo) {
        return toAjax(eduVideoService.updateEduVideo(eduVideo));
    }

    /**
     * 删除课程视频
     */
    @RequiresPermissions("edu:video:remove")
    @Log(title = "课程视频", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(eduVideoService.deleteEduVideoByIds(ids));
    }
}
